package main

import (
	"bytes"
	"crypto/tls"
	"crypto/x509"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"time"
)

func main() {
	strs := []string{"a", "b", "c"}
	data := make(map[string]interface{})
	data["data"] = strs
	b, err := json.Marshal(data)
	if err != nil {
		fmt.Println(err)
		return
	}
	req, err := http.NewRequest(http.MethodPost, "https://127.0.0.1:8080/test", bytes.NewReader(b))


	caCert, err := ioutil.ReadFile("rootCA.crt")
	if err != nil {
		log.Fatal(err)
	}
	caCertPool := x509.NewCertPool()
	caCertPool.AppendCertsFromPEM(caCert)
	client := &http.Client{
		Timeout: time.Second * 3,
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				RootCAs: caCertPool,
			},
		},
	}
	res, err := client.Do(req)
	if err != nil {
		fmt.Println(err)
		return
	}
	all, err := ioutil.ReadAll(res.Body)
	if err != nil {
		fmt.Printf("read err:%v", err)
		return
	}
	fmt.Println(string(all))
}
